package ar.edu.unq.wannaplay.panels.calendar;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.model.PropertyModel;

import ar.edu.unq.wannaplay.pages.calendar.CalendarViewPage;
import ar.edu.unq.wannaplay.panels.WPListViewPanel;
import ar.edu.unq.wannaplay.services.EmployeeService;
import ar.edu.unq.wannaplay.utils.CalendarHelper;
import ar.edu.unq.wannaplay.utils.CalendarListView;

public class CalendarViewPanel extends WPListViewPanel<EmployeeService> {
    private static final long serialVersionUID = 1L;

    private CalendarHelper helper;

    public CalendarViewPanel(final String id, final EmployeeService service) {
        super(id, service, new String[] { "employee", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
                "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
                "30", "31" });
        this.initialize();
    }

    private void initialize() {
        this.add(this.prepareHeaderLabel("headers"));
        helper = CalendarHelper.getInstance(this.getService());
        this.addLabels();
        this.addNavigator();
        CalendarListView calendarListView = new CalendarListView("populatedList", this.getService(), this.getLabels(),
                this, helper.getData());
        this.add(calendarListView);
        this.add(new PagingNavigator("navigator", calendarListView));
    }

    private void addLabels() {
        this.add(new Label("monthNumber", new PropertyModel<CalendarHelper>(helper, "month")));
        this.add(new Label("yearNumber", new PropertyModel<CalendarHelper>(helper, "year")));
    }

    private void addNavigator() {
        this.add(new Link("nextMonth") {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick() {
                helper.nextCalendar();
                this.setResponsePage(CalendarViewPage.class);
            }
        });

        this.add(new Link("prevMonth") {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick() {
                helper.prevCalendar();
                this.setResponsePage(CalendarViewPage.class);
            }
        });

    }

    public CalendarHelper getHelper() {
        return helper;
    }

    public void setHelper(final CalendarHelper helper) {
        this.helper = helper;
    }
}